package com.xiaoyao.novel.action.page;

import org.apache.log4j.Logger;

import com.xiaoyao.novel.common.Pagin;
import com.xiaoyao.novel.pojo.Admin;
import com.xiaoyao.novel.service.AdminService;

public class AdminAction extends BaseAction {
	private static Logger logger = Logger.getLogger(AdminAction.class);
	private static final long serialVersionUID = 1L;
	private AdminService adminService = new AdminService();
	private Admin admin;
	private Pagin pagin = new Pagin();

	@Override
	public String execute() throws Exception {
		return search();
	}

	public String search() throws Exception {
		// 处理数据
		adminService.search(pagin);
		request.setAttribute("pagin", pagin);
		return SUCCESS;
	}

	/**
	 * 跳转到增加界面,获取到所有权限
	 * 
	 * @return
	 */
	public String showAddAdmin() {
		// List<Role> roleList;
		return "showAddAdmin";
	}

	/**
	 * 增加管理员
	 * 
	 * @return
	 */
	public String addAdmin() {
		adminService.insert( admin);
		return "addSuccess";
	}

	public String showModify() {
		Admin modifyAdmin = adminService.getById(admin.getAid());
		request.setAttribute("admin", modifyAdmin);
		return "showModify";
	}

	public String modifyAdmin() { 
		adminService.update(admin);
		return "modifySuccess";
	}

	public String deleteAdmin() {
		adminService.delete(admin.getAid()); 
		return "deleteSuccess";
	}

	public AdminService getAdminService() {
		return adminService;
	}

	public void setAdminService(AdminService adminService) {
		this.adminService = adminService;
	}

	public Admin getAdmin() {
		return admin;
	}

	public void setAdmin(Admin admin) {
		this.admin = admin;
	}

	public Pagin getPagin() {
		return pagin;
	}

	public void setPagin(Pagin pagin) {
		this.pagin = pagin;
	}

}
